﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using Newtonsoft.Json;
using SuSPExtension;
using System;

public class AppConfig : Singleton<AppConfig> {

    const string key_app_config = "key_app_config";
    private AppConfigData configData;

    public AppConfigData AppConfigData {
        get {
            return configData;
        }
    }

    public override void Init()
    {
        base.Init();
        LoadConfig();
    }

    public void LoadConfig()
    {
        if (PlayerPrefs.HasKey(key_app_config))
        {
            string jsonStr = PlayerPrefs.GetString(key_app_config);
            configData = JsonConvert.DeserializeObject<AppConfigData>(jsonStr);
        }
        else
        {
            configData = GetDefaultAppConfig();
        }
    }

    public void WriteConfig()
    {
        if (configData != null)
        {
            string jsonStr = JsonConvert.SerializeObject(configData);
            PlayerPrefs.SetString(key_app_config, jsonStr);
        }
    }

    private AppConfigData GetDefaultAppConfig()
    {
        return new AppConfigData() {
             isEnableEffect = true,
              lastid = "test"
        };
    }
}

public class AppConfigData
{
    public string lastid;
    public bool isEnableEffect;
}


